class Solution(object):
    def reverse(self, x):
        """
        :type x: int
        :rtype: int
        """
        max = 2147483647
        min = -2147483648

        rs = 0
        nage = False

        if x<0:
            x=-1*x
            nage=True

        try:
            while x != 0:
                rs = int(rs*10 + x%10)
                x = int(x/10)
            if rs<min or rs>max:
                return 0
            else:            
                if nage:
                    return -1*rs
                else:
                    return rs
        except YichuError:
            return 0



s=Solution()

print(s.reverse(121))